<?php include $this->admin_tpl('meta', 'admin');?>
<title>库存趋势统计</title>
<meta name="referrer" content="no-referrer" />
<style>
.label{margin-left:3px;height:20px;line-height:20px;}
</style>
</head>
<body>
<div class="page-container">
	<div style="font-size:16px;font-weight:bold;text-align:center;position:relative;"><span class="c-primary">
		<a onclick="layer.load();" href="<?php echo U('jst_snapshot',['days'=>'30']);?>"><span class="label <?php if($days=='30'){ echo 'label-secondary'; }else{ echo 'label-primary'; } ?> radius">近30天</span></a>
		<a onclick="layer.load();" href="<?php echo U('jst_snapshot',['days'=>'1year']);?>"><span class="label <?php if($days=='1year'){ echo 'label-secondary'; }else{ echo 'label-primary'; } ?> radius">近一年</span></a>
		<a onclick="layer.load();" href="<?php echo U('jst_snapshot',['days'=>'2year']);?>"><span class="label <?php if($days=='2year'){ echo 'label-secondary'; }else{ echo 'label-primary'; } ?> radius">近两年</span></a>
		<span class="f-r" style="position:absolute;top:3px;right:10px;">
			 <span class="select-box inline" style="background:#fff;">
				<select name="brand" class="select select_brand">
					<option value="0">所有品牌</option>
					<?php 		
					foreach(get_brand_list() as $val){
						$str = '';
						echo '<option value="'.$val.'" '.$str.'>'.$val.'</option>';
					}
					?>
				</select>
			</span>
			<input name="is_ys_checkbox" type="checkbox" checked> 佑晟
		</span>
	</div>
	<div id="container" style="height:400px;"></div>
</div>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/echarts/echarts.min.js"></script>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('container'));
var dom = document.getElementById('container');
var myChart = echarts.init(dom, null, {
  renderer: 'canvas',
  useDirtyRect: false
});
var app = {};
var option;
$('input[name="is_ys_checkbox"]').click(function(){
	$('select[name="brand"]').val("0");
	snapshot();
});
function setOption(res){
	myChart.clear();
	myChart.setOption({
		tooltip: {
			trigger: 'axis',
			axisPointer:{
				lineStyle:{
					width:2,
					color:'#54A0FF'
				}
			}
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		xAxis: [{
			type: 'category',
			data: res.date,
			boundaryGap: false,
		}],
		yAxis: [{
			type: 'value',
			min: res.min
		}],
		series: res.data,
		dataZoom: [{
			type: 'slider', // 这个是直角坐标系中使用的
			show: true,
			xAxisIndex: [0],
			start: 0,
			end: 100
		}]
	})
}
var res = <?php echo $res;?>;
setOption(res);


$('.select_brand').change(function(){
	if($(this).val() != 0){
		$('input[name="is_ys_checkbox"]').attr("checked", false);
	}
	snapshot();
})

function snapshot(){
	let brand = $('select[name="brand"]').val();
	let is_ys = $('input[name="is_ys_checkbox"]').is(':checked') ? 1 : 0;
	let days = '<?php echo $days; ?>'; // 从PHP获取当前选中的days
	$.ajax({
		type: 'GET',
		url: "<?php echo U('jst_snapshot');?>",
		data: {is_ys:is_ys,brand:brand,is_ajax:1,days:days},
		dataType: "json",
		success: function (res) {
			setOption(res);
		}
	});
}

</script> 

</body>
</html>